/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * aProductPanel.java
 *
 * Created on 19/11/2009, 02:42:06
 */

package desktopapplication3;

import backend.Product;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author santiago
 */
public class aProductPanel extends javax.swing.JPanel {
    private int languagecode;
    private Product aProd;
    private org.jdesktop.application.ResourceMap resourceMap2 = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(VentanaPrincipal.class);
    /** Creates new form aProductPanel */

    public aProductPanel(Product p,int languagecode) {
        this.languagecode=languagecode;
        this.aProd=p;
        
        //initMyComponents();
        
        initComponents();

        Icon preview=null;

        try {
            
            URL url = new URL(aProd.getImage());
            preview = new ImageIcon( DesktopApplication3.getScaledImage((new ImageIcon( url )).getImage(),200,240) );

        } catch (MalformedURLException ex) {
            
           JOptionPane.showMessageDialog(this, resourceMap2.getString("ERROR_1534"));
           System.exit(1);
        }

        imagen.setIcon( preview );
        titulo.setText(aProd.getName());
        productRank.setText(((Double)aProd.getRank()).toString());
        productPrice.setText(((Double)aProd.getPrice()).toString());


    }


    private void initMyComponents(){
        titulo = new javax.swing.JLabel();
        Ranking = new javax.swing.JLabel();
        Precio = new javax.swing.JLabel();
        productRank = new javax.swing.JLabel();
        productPrice = new javax.swing.JLabel();
        imagen = new javax.swing.JLabel();
        expandInfo = new javax.swing.JButton();
        /*Image a=null;
        try {
             a = (new JApplet()).getImage(new URL(aProd.getImage()));
        } catch (MalformedURLException ex) {
            Logger.getLogger(aProductPanel.class.getName()).log(Level.SEVERE, null, ex);
        }*/
        Icon preview=null;
        try {
            preview = new ImageIcon(new URL(aProd.getImage()));
        } catch (MalformedURLException ex) {
           JOptionPane.showMessageDialog(this, this.resourceMap2.getString("ERROR_1534"));
        }
//        imagen.setIcon(preview);
        
       setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
       setName("Form"); // NOI18N
       addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(aProductPanel.class);
        titulo.setFont(resourceMap.getFont("titulo.font")); // NOI18N
        titulo.setText(aProd.getName()); // NOI18N
        titulo.setName("titulo"); // NOI18N

        Ranking.setFont(resourceMap.getFont("Ranking.font"));
        Ranking.setText(resourceMap.getString("Ranking.text")); // NOI18N
        Ranking.setName("Ranking"); // NOI18N

        Precio.setFont(resourceMap.getFont("Ranking.font"));
        Precio.setText(resourceMap.getString("Precio.text")); // NOI18N
        Precio.setName("Precio"); // NOI18N

        productRank.setText(((Double)aProd.getRank()).toString()); // NOI18N
        productRank.setName("productRank"); // NOI18N

        productPrice.setText(((Double)aProd.getPrice()).toString()); // NOI18N
        productPrice.setName("productPrice"); // NOI18N

        expandInfo.setText(resourceMap.getString("expandInfo.text")); // NOI18N
        expandInfo.setToolTipText(resourceMap.getString("expandInfo.toolTipText")); // NOI18N
        expandInfo.setName("expandInfo"); // NOI18N
        expandInfo.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                viewButton();
            }
        });

        //imagen.setText(resourceMap.getString("imagen.text")); // NOI18N

        imagen.setIcon(preview);
        imagen.setName("imagen"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(Ranking)
                        .addGap(18, 18, 18)
                        .addComponent(productRank))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Precio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(expandInfo)
                            .addComponent(productPrice))))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addComponent(titulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(94, 94, 94))
            .addGroup(layout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(57, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(titulo, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imagen, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Ranking)
                    .addComponent(productRank))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Precio)
                    .addComponent(productPrice))
                .addGap(18, 18, 18)
                .addComponent(expandInfo)
                .addContainerGap(23, Short.MAX_VALUE))
        );
        

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titulo = new javax.swing.JLabel();
        Ranking = new javax.swing.JLabel();
        Precio = new javax.swing.JLabel();
        productRank = new javax.swing.JLabel();
        productPrice = new javax.swing.JLabel();
        imagen = new javax.swing.JLabel();
        expandInfo = new javax.swing.JButton();
        productPrice1 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getResourceMap(aProductPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setMaximumSize(new java.awt.Dimension(225, 288));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(225, 288));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
        });
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        titulo.setFont(resourceMap.getFont("titulo.font")); // NOI18N
        titulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titulo.setText(resourceMap.getString("titulo.text")); // NOI18N
        titulo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        titulo.setName("titulo"); // NOI18N
        add(titulo, new org.netbeans.lib.awtextra.AbsoluteConstraints(23, 20, 210, -1));

        Ranking.setFont(resourceMap.getFont("Ranking.font")); // NOI18N
        Ranking.setText(resourceMap.getString("Ranking.text")); // NOI18N
        Ranking.setName("Ranking"); // NOI18N
        add(Ranking, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 250, -1, -1));

        Precio.setFont(resourceMap.getFont("Ranking.font")); // NOI18N
        Precio.setText(resourceMap.getString("Precio.text")); // NOI18N
        Precio.setName("Precio"); // NOI18N
        add(Precio, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 270, -1, -1));

        productRank.setText(resourceMap.getString("productRank.text")); // NOI18N
        productRank.setName("productRank"); // NOI18N
        add(productRank, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 250, -1, -1));

        productPrice.setFont(resourceMap.getFont("productPrice1.font")); // NOI18N
        productPrice.setForeground(resourceMap.getColor("productPrice.foreground")); // NOI18N
        productPrice.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        productPrice.setText(resourceMap.getString("productPrice.text")); // NOI18N
        productPrice.setName("productPrice"); // NOI18N
        add(productPrice, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 270, 60, -1));

        imagen.setText(resourceMap.getString("imagen.text")); // NOI18N
        imagen.setName("imagen"); // NOI18N
        add(imagen, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 50, 170, 180));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(desktopapplication3.DesktopApplication3.class).getContext().getActionMap(aProductPanel.class, this);
        expandInfo.setAction(actionMap.get("viewButton")); // NOI18N
        expandInfo.setText(resourceMap.getString("expandInfo.text")); // NOI18N
        expandInfo.setToolTipText(resourceMap.getString("expandInfo.toolTipText")); // NOI18N
        expandInfo.setName("expandInfo"); // NOI18N
        add(expandInfo, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 260, -1, -1));

        productPrice1.setFont(resourceMap.getFont("productPrice1.font")); // NOI18N
        productPrice1.setForeground(resourceMap.getColor("productPrice1.foreground")); // NOI18N
        productPrice1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        productPrice1.setText(resourceMap.getString("productPrice1.text")); // NOI18N
        productPrice1.setName("productPrice1"); // NOI18N
        add(productPrice1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 270, 40, 20));
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        /*Aca es donde se especifica el lenguaje para toda la parte de las categorias*/
       // aProdInfoFrame view = new aProdInfoFrame(aProd,languagecode);
       // view.setVisible(true);
       // view.setLocationRelativeTo(null);
    
    }//GEN-LAST:event_formMouseClicked

    private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
        //this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    }//GEN-LAST:event_formMouseEntered

    @Action
    public void viewButton(){
        aProdInfoFrame view = new aProdInfoFrame(aProd,languagecode);
        view.setVisible(true);
        view.setLocationRelativeTo(null);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Precio;
    private javax.swing.JLabel Ranking;
    private javax.swing.JButton expandInfo;
    private javax.swing.JLabel imagen;
    private javax.swing.JLabel productPrice;
    private javax.swing.JLabel productPrice1;
    private javax.swing.JLabel productRank;
    private javax.swing.JLabel titulo;
    // End of variables declaration//GEN-END:variables

}
